package com.haoze.common.model;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.haoze.common.enumeration.StateEnum;

import javax.persistence.Column;
import java.util.Date;

/**
 * @author yangyb
 * @date 2018/12/6
 */
public class BaseEntity {
    /**
     * 数据版本
     */
    @Column(name = "DATA_VERSION")
    protected Integer dataVersion;

    @Column(name = "GMT_CREATE")
    protected Date createTime;

    @Column(name = "GMT_MODIFY")
    protected Date modifyTime;
    /**
     * 医疗机构
     */
    @Column(name = "HOSPITAL_ID")
    protected String hospitalId;


    public Integer getDataVersion() {
        return dataVersion;
    }

    public void setDataVersion(Integer dataVersion) {
        this.dataVersion = dataVersion;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    public String getHospitalId() {
        return hospitalId;
    }

    public void setHospitalId(String hospitalId) {
        this.hospitalId = hospitalId;
    }

    public void initAdd() {
        this.setDataVersion(1);
        this.setHospitalId(StateEnum.HOSPITAL_ID.getValue());
        this.setCreateTime(new Date());
        this.setModifyTime(new Date());
    }

    public void initUpdate() {
        this.setDataVersion(this.getDataVersion() == null ? 1 : this.getDataVersion() + 1);
        this.setHospitalId(StateEnum.HOSPITAL_ID.getValue());
        this.setModifyTime(new Date());
    }
}
